# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Miles McLean <mills00013@gmail.com>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Brad Pitcher <bradpitcher@gmail.com>
# Contributor: Moritz Lipp <mlq@pwmt.org>

pkgname=networkmanager-l2tp
pkgver=1.20.8
_pppver=2.4.9
pkgrel=1
pkgdesc='L2TP support for NetworkManager'
arch=(loong64 x86_64)
url='https://github.com/nm-l2tp/NetworkManager-l2tp'
license=(GPL2)
conflicts=(networkmanager-l2tp-gtk3 networkmanager-l2tp-gtk4)
replaces=(networkmanager-l2tp-gtk3 networkmanager-l2tp-gtk4)
depends=(ppp=$_pppver xl2tpd)
makedepends=(intltool libnma libnma-gtk4 python)
optdepends=(
  'libnma: GUI support (GTK 3)'
  'libnma-gtk4: GUI support (GTK 4)'
  'strongswan: IPSec support')
source=("$pkgname-$pkgver.tar.gz"::"$url/archive/$pkgver.tar.gz")
b2sums=('de8e8b5bf01ecacfc2727807725062f5252d72b376e8931f0d821aacc150c0f11bcbce0d7f1a7257565be7c34d2d7e6e974bb0f5b181502aec7a6dfb3bcd706b')

prepare() {
  ln -sf NetworkManager-l2tp-$pkgver $pkgname-$pkgver
}

build() {
  export NOCONFIGURE=1
  cd $pkgname-$pkgver
  ./autogen.sh
  ./configure \
    --libexecdir=/usr/lib/NetworkManager \
    --localstatedir=/var \
    --prefix=/usr \
    --sysconfdir=/etc \
    --with-pppd-plugin-dir=/usr/lib/pppd/$_pppver \
    --with-gtk4
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  make -C $pkgname-$pkgver DESTDIR="$pkgdir" install
  install -Dm644 $pkgname-$pkgver/NEWS "$pkgdir/usr/share/doc/$pkgname/NEWS"
}
